# ifndef __Load_H_
# define __Load_H_

extern volatile bool g_bLoading;
extern volatile bool g_bStop;

typedef std::list<string_t> file_names_t;

extern file_names_t g_last_file_names;

struct map_t;
void LoadMap (const char * _strFileName,       size_t _cFileType, bool _bRemoveOldMap, map_t & _map);
void LoadMap (const file_names_t & _FileNames, size_t _cFileType, bool _bRemoveOldMap, map_t & _map);
void WaitLoadThread ();
void StopLoadThread ();

////////////////////////////////////////////////////////////

# include "FileTypeInfo.h"

class CMapLoader {
  public:
	virtual bool IsValid (const char * _pData, size_t _cFileSize) const = 0;

	// NOTE: _strFileName is supplied to get folder path, if this is required to locate some referred files.
	virtual LoadStatus_t Load (const char * _pData, size_t _cFileSize, const char * _strFileName, map_t * _pMap) = 0;

	static LoadStatus_t LoadFile (const char * _strFileName, map_t * _pMap, const CFileTypeInfo ** _ppSaverInfo);
};

# define DECLARE_MAP_LOADER_impl(_T,_strClass,_strExt,_strFilter,_dwFlags) \
	static CMapLoader * _Create_##_T () {return new _T;} \
	static CFileTypeInfo _Creator_##_T (& _Create_##_T, NULL, _strClass, _strExt, _strFilter, (_dwFlags));

# define DECLARE_MAP_LOADER(_T,_strClass,_strExt,_strFilter)         DECLARE_MAP_LOADER_impl (_T, _strClass, _strExt, _strFilter, 0)
# define DECLARE_DEFAULT_MAP_LOADER(_T,_strClass,_strExt,_strFilter) DECLARE_MAP_LOADER_impl (_T, _strClass, _strExt, _strFilter, ftiDefault)
# define DECLARE_MAP_IMPORT(_T,_strClass,_strExt,_strFilter)         DECLARE_MAP_LOADER_impl (_T, _strClass, _strExt, _strFilter, ftiImportExport)
# define DECLARE_WPTRK_LOADER(_T,_strClass,_strExt,_strFilter,_Flgs) DECLARE_MAP_LOADER_impl (_T, _strClass, _strExt, _strFilter, _Flgs)

////////////////////////////////////////////////////////////

struct rect_t;
struct point_t;

class CMapRenderer : public CMapLoader {
  public:
	virtual void GetRect (rect_t & _rect, long & _lWidth, long & _lHeight) const = 0;
	virtual void Draw (HDC _hDC, const rect_t & _rectVisible, const point_t & _ptCorrectionShift, long _lShiftX, long _lShiftY) const = 0;
};

# define DECLARE_MAP_RENDERER(_T,_strClass,_strExt,_strFilter)        DECLARE_MAP_LOADER_impl (_T, _strClass, _strExt, _strFilter, ftiRenderer)
# define DECLARE_MAP_RENDERER_NO_MMF(_T,_strClass,_strExt,_strFilter) DECLARE_MAP_LOADER_impl (_T, _strClass, _strExt, _strFilter, ftiRenderer | ftiDontMapFile)

# endif // __Load_H_